//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
//          VisualNovelToolkit           /_/_/_/_/_/_/_/_/_/.
// Copyright ©2013 - Sol-tribe. /_/_/_/_/_/_/_/_/_/.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.

using UnityEditor;
using UnityEngine;

namespace ViNoToolkit{

    public class ActorCreateWizard : ScriptableWizard {
        public string actorName;
        public float sizeInPercent = 100f;
        public Color textColor = Color.white;
        public Texture2D[] textures;    

        [MenuItem ("GameObject/Create Actor Data")]
        static void CreateWizard () {
            ScriptableWizard.DisplayWizard<ActorCreateWizard>("Create your Actor", "Create" );
        }

        [MenuItem( "Assets/Add an actor to scene...")]
        static public void AddActorToScene(){
            Texture2D tex = Selection.activeObject as Texture2D;
            if( tex ){                
                SceneEvent se = GameObject.FindObjectOfType(typeof(SceneEvent)) as SceneEvent;
                foreach( ActorInfo a in se.actorLib.actorEntries ){
                    if( a.name == tex.name ){
                        EditorUtility.DisplayDialog( "Warning" , "The Texture name Actor is already exist." , "ok" );
                        return;
                    }
                }

                Texture2D[] textures = new Texture2D[ 1 ];
                textures[ 0 ] = tex;
                ActorInfo actor = CreateActor( tex.name , 100f , Color.white ,  textures );

                if( se && se.actorLib ){
                    ArrayUtility.Add<ActorInfo>( ref se.actorLib.actorEntries , actor );
                    ViNoEditorGUILayout.CollectActorNamesInActorLibrary();
                }
            }
        }

        static public ActorInfo CreateActor( string actorName , float sizeInPercent , Color textColor , Texture2D[] textures ){
            if( ! System.IO.Directory.Exists( "Assets/Actors") ){
                AssetDatabase.CreateFolder( "Assets" , "Actors" );
            }

            ActorInfo actor = ScriptableObjectUtility.CreateScriptableObject( "ActorInfo" , "Assets/Actors/" + actorName + ".asset") as ActorInfo;
            ActorUtility.SetUpActorInfo( actor , actorName , sizeInPercent , textColor , textures );
            EditorGUIUtility.PingObject( actor );  

            return actor;
        }

        void OnWizardCreate () {
            EditorUtility.DisplayDialog( "Note" , "Please check that the Actor Texture is placed at under a \"Resources/\" folder." , "ok" );

            CreateActor( actorName , sizeInPercent , textColor , textures );
        }  
        
    }
}